var firstMissingPositive = function (nums) {
  let l = nums.length
  for (let i = 0; i < nums.length; i++) {
    if (nums[i] <= 0) {
      nums[i] = l + 1
    }
  }
  for (let i = 0; i < l; i++) {
    let num = Math.abs(nums[i])
    if (num <= l) {
      // 这里神之一手
      nums[num - 1] = -Math.abs(nums[num - 1])
    }
  }
  for (let i = 0; i < l; i++) {
    if (nums[i] > 0) {
      return i + 1
    }
  }
  return l + 1
}
/**
 * 长度1-N的数组，没有出现最小的数的范围为[1, N+1]
 */
// console.log(firstMissingPositive([1, 2, 0]))
// console.log(firstMissingPositive([7, 8, 9, 11, 12]))
// console.log(firstMissingPositive([3, 4, -1, 1]))
// console.log(firstMissingPositive([9, 8, 7, 6, 5, 4, 3, 2, 1]))
console.log(firstMissingPositive([3, 4, -1, 1, 9, -5]))